<template>
  <div class="create-or-edit">
  
  </div>
</template>

<script>
import { getPositionList } from "@/services/front-api";
import CourseImage from "./CourseImage";
import { addAdmin, editTeacherInfo } from "@/services/userManager";
export default {
  name:'editTeacher',
  components: {
    CourseImage,
  },
  data() {
    return {
      userInfo: {},
      positionList: [],
    };
  },
  props: ["teacherInfo"],
  methods: {
    onCancel() {
      // 设置取消状态，让父组件处理
      this.$emit("cancel");
    },
    async onSubmit() {
      if (this.teacherInfo.id) {
        await editTeacherInfo(this.userInfo);
      } else {
        await addAdmin(this.userInfo);
      }
      this.$emit("success");
      this.$message.success("添加成功");
    },
    loadInfo() {
      console.log(11)
      if (this.teacherInfo != {}) {
        Object.keys(this.teacherInfo).forEach((key) => {
          this.userInfo[key] = this.teacherInfo[key];
        });
      } else {
        this.userInfo = {
          userName: "",
          password: "",
          sex: "男",
          position: "",
          userImg: "",
        };
      }
    },
    async loadPosistionAll() {
      const { data } = await getPositionList();
      this.positionList = data.data;
    },
  },
  created() {
    this.loadPosistionAll();
    this.loadInfo();
  },
};
</script>

<style lang="scss" scoped></style>
